package lcr;

public class Test0014 {
    public static void main(String[] args) {
        new Solution0014_1().checkInclusion("ab","eidboaoo");
    }
}

class Solution0014_1 {
    public boolean checkInclusion(String s1, String s2) {
        char[] charArray = s1.toCharArray();
        int[] nums = new int[26];
        for (char c : charArray) {
            nums[c - 'a']++;
        }

        char[] chars = s2.toCharArray();
        int flag = s1.length();
        for (int i = 0; i < chars.length; i++) {
            int index = chars[i] - 'a';
            nums[index]--;
            if (nums[index] >= 0) flag--;
            else flag++;
            if (i >= s1.length()) {
                int index1 = chars[i - s1.length()] - 'a';
                nums[index1]++;
                if (nums[index1] > 0) flag++;
                else flag--;
            }
            if(flag == 0) return true;
        }
        return false;
    }
}